//
//  BaseViewController.m
//  Upoint
//
//  Created by iKing on 2017/5/10.
//  Copyright © 2017年 iKing. All rights reserved.
//

#import "BaseViewController.h"
#import "AppDelegate.h"


@interface BaseViewController ()
@property (nonatomic, assign) BOOL isSelect;
@end

@implementation BaseViewController
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = YES;
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = lineGray;
}

#pragma mark title
- (void)loadBaseTitleLable:(NSString *)title
{
    // 自定义导航栏背景
    self.navTitleBgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, SafeAreaTopHeight)];
    self.navTitleBgView.backgroundColor = navBarColor;
    //    self.navTitleBgView.image = UIImageNamed(@"navBGImg");
    self.navTitleBgView.userInteractionEnabled = YES;
    [self.view addSubview:self.navTitleBgView];
    
    // 左按钮
    _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_leftBtn setImage:UIImageNamed(@"backwhite") forState:(UIControlStateNormal)];
    //    [_leftBtn sizeToFit];
    [_leftBtn addTarget:self action:@selector(backV) forControlEvents:(UIControlEventTouchUpInside)];
    [self.navTitleBgView addSubview:_leftBtn];
    [_leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.navTitleBgView);
        make.left.equalTo(_navTitleBgView);
        make.size.mas_offset(CGSizeMake(40, 45));
    }];
    // S左按钮
    _SLeftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_SLeftBtn setImage:UIImageNamed(@"backwhite") forState:(UIControlStateNormal)];
    [self.navTitleBgView addSubview:_SLeftBtn];
    [_SLeftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.navTitleBgView);
        make.left.equalTo(_navTitleBgView);
        make.size.mas_offset(CGSizeMake(40, 45));
    }];
    _SLeftBtn.hidden = YES;
    
    // title
    self.NavTitleLable = [UILabel labelWithText:title textColor:[UIColor whiteColor] fontSize:17];
    [self.NavTitleLable sizeToFit];
    [self.navTitleBgView addSubview:self.NavTitleLable];
    [self.NavTitleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.navTitleBgView);
        make.centerY.equalTo(_leftBtn);
    }];
    // 右按钮
    _rightBtn = [UIButton buttonWithTitle:@"" fontSize:14 titleColor:UIColorWhite background:kClearColor cornerRadius:0];
    [_rightBtn sizeToFit];
    [self.navTitleBgView addSubview:_rightBtn];
    [_rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.NavTitleLable);
        make.right.equalTo(self.navTitleBgView).offset(-rateWidth(30));
    }];
    _rightBtn.hidden = YES;
}
- (void)loadWhiteTitleLable:(NSString *)title
{
    // 自定义导航栏背景
    self.navTitleBgView  = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, SafeAreaTopHeight)];
    self.navTitleBgView.backgroundColor = UIColorWhite;
    //    self.navTitleBgView.image = UIImageNamed(@"navBGImg");
    self.navTitleBgView.userInteractionEnabled = YES;
    [self.view addSubview:self.navTitleBgView];
    
    // 左按钮
    UIImageView *arrow = [[UIImageView alloc] init];
    arrow.image = UIImageNamed(@"fanhui-black");
    [arrow sizeToFit];
    [self.navTitleBgView addSubview:arrow];
    [arrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.navTitleBgView).offset(17);
        make.bottom.equalTo(self.navTitleBgView).offset(-17);
    }];
    
    _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_leftBtn addTarget:self action:@selector(backV) forControlEvents:(UIControlEventTouchUpInside)];
    [self.navTitleBgView addSubview:_leftBtn];
    [_leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(arrow);
        make.left.equalTo(_navTitleBgView).offset(rateWidth(10));
        make.size.mas_equalTo(CGSizeMake(50, 40));
    }];
    
    // title
    self.NavTitleLable = [UILabel labelWithText:title textColor:UIColorWithRGB(36, 36, 36) fontSize:19];
    [self.NavTitleLable sizeToFit];
    [self.navTitleBgView addSubview:self.NavTitleLable];
    [self.NavTitleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.navTitleBgView);
        make.centerY.equalTo(arrow);
    }];
    
    // 右按钮
    _rightBtn = [UIButton buttonWithTitle:@"历史记录" fontSize:14 titleColor:UIColorWhite background:kClearColor cornerRadius:0];
    [_rightBtn sizeToFit];
    [self.navTitleBgView addSubview:_rightBtn];
    [_rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.NavTitleLable);
        make.right.equalTo(self.navTitleBgView).offset(-rateWidth(30));
    }];
    _rightBtn.hidden = YES;
    
    //    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 64-0.5, kScreenWidth, 0.5)];
    //    line.backgroundColor = UIColorWithRGB(231, 230, 230);
    //    [self.navTitleBgView addSubview:line];
    //    self.line = line;
}


- (void)backV
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark 颜色渐变
- (void)loadLocation:(UIView *)view
{
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.colors = @[(__bridge id)UIColorWithRGB(0, 124, 209).CGColor, (__bridge id)UIColorWithRGB(0, 181, 250).CGColor];
    gradientLayer.locations = @[@0.2];
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(1.0, 0);
    gradientLayer.frame = CGRectMake(0, 0, view.width, view.height);
    [view.layer addSublayer:gradientLayer];
}

- (void)clickView:(UIView *)view  cornerRadius:(CGFloat)cornerRadius
{
    view.layer.cornerRadius = cornerRadius;
    view.layer.masksToBounds = YES;
}
@end
